package com.siashan.toolkit.validation.validator;


import com.siashan.toolkit.validation.EnumValue4String;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


/**
 * 枚举之校验
 *
 * @author siashan
 * @since 2021/7/9 1:41 上午
 */
public class EnumValue4StringValidator implements ConstraintValidator<EnumValue4String, Object> {

    private String[] strValues;

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {

        for (String s : strValues) {
            if (s.equals(o)) {
                return true;
            }
        }

        return false;
    }

    @Override
    public void initialize(EnumValue4String constraintAnnotation) {
        strValues = constraintAnnotation.strValues();
    }
}
